<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/26
 * Time: 8:53
 */

namespace app\index\controller;


use think\Container;
use think\facade\Config;

class Demo1
{
    public function getName($name = 'vip'){
        echo 'hello ',$name;
    }

    public function getMethod(\app\common\Temp $temp){
        $temp->setName('哈哈');
        return $temp->getName();
    }

    public function bindClass(){
    	Container::set('temp', '\app\common\Temp');
    	$temp = Container::get('temp', ['name'=>'顶顶顶顶顶']);
    	return $temp->getName();
    }
    # 函数助手的方式绑定
    public function bindClass2(){
        bind('temp', '\app\common\Temp');
        $temp = app('temp', ['name'=>'顶顶顶顶顶123']);
        return $temp->getName();
    }

    public function bindClosure(){
        Container::set('test', function ($name){
            return $name;
        });
        return Container::get('test', ['name'=>'酷酷酷的']);
    }

    # 普通调用
    public function index($name = '象园头'){
        $test = new \app\common\Test2();
        return $test->hello($name);
    }

    # 静态类调用
    public function index2($name = '象园头2'){
        return \app\facade\Test::hello($name);
    }

    # 静态类调用动态的类
    public function index3($name = '象园头3'){
        \think\Facade::bind('app\facade\Test2', 'app\common\Test2');
        return \app\facade\Test2::hello($name);
    }
}